package Demo04;

/**
 * @ClassName Test
 * @Description 深拷贝
 * @Author 李明忠
 * @Date 2025/5/5 10:51
 * @Version 1.0
 */
class Money implements Cloneable{
    public double m = 99.99;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    Money money = new Money();


    @Override
    protected Object clone() throws CloneNotSupportedException {
        Money money = (Money) this.money.clone();

        Person person = (Person) super.clone();

        //将money赋值给性的Person对象中的money值
        person.money = money;
        return person;
    }

}
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();

        //克隆后
        Person person2 = (Person) person1.clone();
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
        System.out.println("==========================");
        person2.money.m = 10.0;
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
    }
}
